<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    /**
     * 错误信息输出
     *
     * @param string $_message
     * @param null $_data
     * @return array
     */
    protected function _error(string $_message, $_data = null)
    {
        return ['error_message' => $_message, 'data' => $_data ?? []];
    }

    /**
     * 正确信息输出
     *
     * @param string $_message
     * @param null $_data
     * @return array
     */
    protected function _success(string $_message, $_data = null)
    {
        $response = ['success_message' => $_message, 'data' => $_data ?? []];
        
        // 在debug模式下添加SQL查询日志
        if (config('app.debug')) {
            $response['sql_queries'] = \Illuminate\Support\Facades\DB::getQueryLog();
        }
        
        return $response;
    }

    // 不使用 jsonResponses
    protected function _noUseJsonResponses($data): array
    {
        return ['no_use' => true, 'data' => $data];
    }
}
